Hey. Im trying to learn some C basics, I have only some python background and these vogue compiling errors on the silliest things are killing me. Like:
Code:
#include <cs50.h>
#include <stdio.h>
int main(void){
char s1 = get_char("Give me a char: ");
if (s1 == 'a' || 'A'){
printf("OK",s1);
}
else if (s1 == 'd' || 'D'){
printf("OK");
}
}
Console output:
~/workspace/C/ $ make testC2
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow testC2.c -lcrypt -lcs50 -lm -o testC2
testC2.c:7:19: error: use of logical '||' with constant operand [-Werror,-Wconstant-logical-operand]
if (s1 == 'a' || 'A')
^ ~~~
testC2.c:7:19: note: use '|' for a bitwise operation
if (s1 == 'a' || 'A')
^~
|
testC2.c:9:21: error: data argument not used by format string [-Werror,-Wformat-extra-args]
printf("OK",s1);
~~~~ ^
testC2.c:12:24: error: use of logical '||' with constant operand [-Werror,-Wconstant-logical-operand]
else if (s1 == 'b' || 'B')
^ ~~~
testC2.c:12:24: note: use '|' for a bitwise operation
else if (s1 == 'b' || 'B')
^~
|
3 errors generated.
make: *** [testC2] Error
I dont want to do bitwise op, I want to do a simple OR here and idk what is wrong.